package com.xyh.config;

import com.xyh.bean.Cat;
import com.xyh.bean.Person;
import com.xyh.bean.Tomcat;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

@Import({Person.class, MainConfig.MyImportRegistrar.class})
@ComponentScan("com.xyh")
@Configuration
public class MainConfig {
	/**
	 * BeanDefinitionRegistry: Bean定义信息注册中心:图纸中心;
	 * 它里面都是BeanDefinition
	 */
	static class MyImportRegistrar implements ImportBeanDefinitionRegistrar {
		@Override
		public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
			RootBeanDefinition beanDefinition = new RootBeanDefinition();
			beanDefinition.setBeanClass(Tomcat.class);
			registry.registerBeanDefinition("tomcat",beanDefinition);
		}
	}
}
